package com.iap.client.mediator
{
	import com.iap.admin.event.VectorEvent;
	import com.iap.admin.signal.VectorRequestSignal;
	import com.iap.app.AppGlobal;
	import com.iap.client.event.ClientVectorEvent;
	import com.iap.client.event.FilterEvent;
	import com.iap.client.event.VectorRendererEvent;
	import com.iap.client.view.VectorFilterResultView;
	import com.iap.common.mediator.BaseMediator;
	import com.iap.common.model.Tag;
	import com.iap.common.model.VectorTag;
	import com.iap.common.signal.VectorByTagRequestSignal;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	
	public class VectorFilterResultMediator extends BaseMediator
	{
		[Inject]
		public var view:VectorFilterResultView;
		[Inject]
		public var vectorByTagRequest:VectorByTagRequestSignal;

		override public function onRegister():void
		{
			addContextListener(FilterEvent.CHANGE, filterResponseHandler);
			addContextListener(VectorEvent.RESPONSE, vectorResponseHandler);
		}

		private function filterResponseHandler(evt:FilterEvent):void
		{
			var tagIds:Array = [];
			for each(var item:Tag in evt.data)
			{
				tagIds.push(item.id);
			}
			vectorByTagRequest.dispatch(tagIds, VectorByTagRequestSignal.GET);
		}
		
		private function vectorResponseHandler(evt:VectorEvent):void
		{
			view.dataProvider = new ArrayCollection(evt.response.result as Array);
		}
	}
}